package com.zhiche.lisa.mdm.controller.inner;

import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import com.zhiche.lisa.mdm.dto.LisaFeeReceivableDTO;
import com.zhiche.lisa.mdm.service.ITransportationTypeService;
import com.zhiche.lisa.mdm.dao.model.TransportationType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 运输工具类型 接口
 * @since 2018-06-01
 * @author lbl
 */
@RestController
@RequestMapping("/inner/transportType")
@Api(value = "/inner/transportType", description = "运输工具类型",tags={"运输工具类型"})
public class TransportTypeController {

    private static final Logger LOGGER = LoggerFactory.getLogger(TransportTypeController.class);

    @Autowired
    private ITransportationTypeService transportationTypeService;

    @GetMapping(value = "/getAllFleetTransportType")
    @ApiOperation(value = "获取所有板车运输工具类型", notes = "获取所有板车运输工具类型", produces = MediaType.APPLICATION_JSON_VALUE,response = RestfulResponse.class)
    public RestfulResponse<List<TransportationType>> getAllFleetTransportType() {
        LOGGER.info("TransportTypeController.getAllFleetTransportType（获取所有服务类型） params : {} ");

        RestfulResponse<List<TransportationType>> result = new RestfulResponse<>(0,"success",null);
        try {
            String strTosType = "fleet";
            result.setData(transportationTypeService.getTransportType(strTosType));
        } catch (BaseException e) {
            LOGGER.error("TransportTypeController.getAllFleetTransportType ERROR... ", e);
            result = new RestfulResponse<>(-1, e.getMessage(), null);
        }
        return result;
    }
    @GetMapping(value = "/getAllTransportType")
    @ApiOperation(value = "获取所有板车运输工具类型", notes = "获取所有板车运输工具类型", produces = MediaType.APPLICATION_JSON_VALUE,response = RestfulResponse.class)
    public RestfulResponse<List<TransportationType>> getAllTransportType() {
        LOGGER.info("TransportTypeController.getAllTransportType（获取所有服务类型） params : {} ");
        RestfulResponse<List<TransportationType>> result = new RestfulResponse<>(0,"success",null);
        try {
            result.setData(transportationTypeService.getAllTransportType());
        } catch (BaseException e) {
            LOGGER.error("TransportTypeController.getAllTransportType ERROR... ", e);
            result = new RestfulResponse<>(-1, e.getMessage(), null);
        }
        return result;
    }

    @GetMapping(value = "/getTransportTypeById")
    @ApiOperation(value = "根据 id 获取运输工具类型", notes = "根据 id 获取运输工具类型", produces = MediaType.APPLICATION_JSON_VALUE,response = RestfulResponse.class)
    public RestfulResponse<TransportationType> getTransportTypeById(Integer transportTypeId) {
        LOGGER.info("TransportTypeController.getTransportTypeById（根据 id 获取运输工具类型） params : {} ", transportTypeId);
        RestfulResponse<TransportationType> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),CommonEnum.SUCCESS.getText(),null);

        try {
            result.setData(transportationTypeService.getTransportTypeById(transportTypeId));
        } catch (BaseException e) {
            LOGGER.error("TransportTypeController.getTransportTypeById ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("TransportTypeController.getTransportTypeById ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }

        return result;
    }
    @GetMapping(value = "/getTransportTypeByCode")
    @ApiOperation(value = "根据 code 获取运输工具类型", notes = "根据 code 获取运输工具类型", produces = MediaType.APPLICATION_JSON_VALUE,response = RestfulResponse.class)
    public RestfulResponse<TransportationType> getTransportTypeByCode(String transportTypeCode) {
        LOGGER.info("TransportTypeController.getTransportTypeByCode（根据 code 获取运输工具类型） params : {} ", transportTypeCode);
        RestfulResponse<TransportationType> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),CommonEnum.SUCCESS.getText(),null);

        try {
            result.setData(transportationTypeService.getTransportTypeByCode(transportTypeCode));
        } catch (BaseException e) {
            LOGGER.error("TransportTypeController.getTransportTypeByCode ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("TransportTypeController.getTransportTypeByCode ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }

        return result;
    }

    @GetMapping(value = "/getTransportTypeByServiceTypeId")
    @ApiOperation(value = "根据 code 获取运输工具类型", notes = "根据 code 获取运输工具类型", produces = MediaType.APPLICATION_JSON_VALUE,response = RestfulResponse.class)
    public RestfulResponse<List<TransportationType>> getTransportTypeByServiceTypeId(Long serviceTypeId) {
        LOGGER.info("TransportTypeController.getTransportTypeByServiceTypeId（根据 code 获取运输工具类型） params : {} ", serviceTypeId);
        RestfulResponse<List<TransportationType>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),CommonEnum.SUCCESS.getText(),null);

        try {
            result.setData(transportationTypeService.getTransportTypeByServiceTypeId(serviceTypeId));
        } catch (BaseException e) {
            LOGGER.error("TransportTypeController.getTransportTypeByServiceTypeId ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("TransportTypeController.getTransportTypeByServiceTypeId ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }

        return result;
    }

}
